package com.walllee.core.meta;

import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;

import com.walllee.core.dao.BaseDAO;

public class TableMetaDAO extends BaseDAO{
	
	/**
	 * 
	 * @param tableName
	 * @param styleId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<TableMeta> getTableMeta(String tableName , String styleId){
		if ( tableName == null || "".equals(tableName)) return new ArrayList<TableMeta>() ;	
		String sql = "SELECT metaId,tableName,columnName,columnCname,columnType,columnIndex,showType,editType,styleId,isShow,isEdit,isAdd,showWidth,showFormat FROM meta_table where tableName = ? and styleId = ? " ;
		
		Object[] parameters = new Object[2];
		parameters[0] = tableName ;
		if ( styleId != null && styleId.trim().length() > 0){
			parameters[1] = styleId ;
		}else{
			parameters[1] = "default" ;		
		}
		
		List<TableMeta> data = this.getJdbcTemplate().query(sql, parameters, new BeanPropertyRowMapper(TableMeta.class));
		return data;
	}
	

}
